<template>
    <!-- <div>封堵白名单</div> -->
    <a-row>
      <a-col>
        <a-card :bordered="false" style="margin-bottom: 10px">
          <!-- 查询区域 -->
          <div class="search-wrapper-btn">
              <a-button type="link" @click="show = !show">
                <span v-if="!show">展开
                  <a-icon type="down" />
                </span>
                <span v-else>收起
                  <a-icon type="up" />
                </span>
              </a-button>
            </div>
          <div class="table-page-search-wrapper">
            <a-form-model ref="ruleForm" :model="pageFilter" :label-col="labelCol" :wrapper-col="wrapperCol">
              <a-row style="display:flex">
                <a-col :span="6">
                <a-form-model-item label="抽检类型">
                    <a-select style="width:100%" v-model="pageFilter.randomType">
                      <a-select-option value="1">人工抽检</a-select-option>
                      <a-select-option value="2">系统定时抽检</a-select-option>
                    </a-select>
                </a-form-model-item>
              </a-col>
                <a-col :span="6">
                <a-form-model-item label="抽检方式" style="margin-left:0px">
                    <a-select style="width:100%" v-model="pageFilter.randomWay">
                      <a-select-option value="1">按比例</a-select-option>
                      <a-select-option value="2">按数量</a-select-option>
                    </a-select>
                </a-form-model-item>
                </a-col>
                <a-col :span="6">
                <a-form-model-item label="抽检状态" style="margin-left:0px">
                    <a-select style="width:100%" v-model="pageFilter.randomStatus">
                      <a-select-option value="1">待抽取</a-select-option>
                      <a-select-option value="2">待验证</a-select-option>
                      <a-select-option value="3">已完成</a-select-option>
                    </a-select>
                </a-form-model-item>
              </a-col>
                  <a-col :span="6" style="margin-left:0px">
                    <a-space :size="6">
                      <a-button type="primary" @click="onQuery" icon="search">查询</a-button>
                      <a-button @click="onResetForm" icon="reload">重置</a-button>
                    </a-space>
                  </a-col>   
              </a-row>
              <a-col :span="6">
                <a-form-model-item label="抽检周期"  v-if="show">
                    <a-select style="width:100%" v-model="pageFilter.cycle">
                      <a-select-option value="1">日检</a-select-option>
                      <a-select-option value="2">周检</a-select-option>
                      <a-select-option value="3">月检</a-select-option>
                      <a-select-option value="4">年检</a-select-option>
                      <a-select-option value="5">自定义</a-select-option>
                    </a-select>
                </a-form-model-item>
              </a-col>
              <a-col :span="6">
                <a-form-model-item label="抽检范围"  v-if="show">
                    <a-range-picker v-model="pageFilter.time"
                    format="YYYY-MM-DD" valueFormat="YYYY-MM-DD hh:mm:ss" @change="onTimeChange" />
                </a-form-model-item>
              </a-col>
            </a-form-model>
          </div>
        </a-card>
        <a-card :bordered="false">
          <div>
            <a-button type="primary" @click="Add" style="margin-right:10px">手工抽检</a-button>
            <z-table ref="table" rowKey="id" :showAlert="false" :showSelection="true" :loading="loading"
              :columns="columns" :dataSource="pageData" @selectedRowKey="onSelectedRow" @change="onTableChange">
              <template slot="action" slot-scope="text, record">
                    <a-button type="link" @click="Edit(record)" v-if="record.randomStatus != 3">编辑</a-button>
                    <a-button type="link" @click='yanzheng(record)' v-if="record.randomStatus == 2">验证</a-button>
                    <a-button type="link" @click="Details(record)" v-if="record.randomStatus == 3">详情</a-button>
                    <a-button type="link" @click="Report" v-if="record.randomStatus == 3">查看报告</a-button>
              </template>
            </z-table>
          </div>
        </a-card>
      </a-col>
    </a-row>
  </template>
  
  <script>
  import { pageBlockingHandRandom,modifyBlockingHandRandom } from '@/api/plugging/Police'
  export default {
    mounted () {
      this.onQuery()
    },
    data () {
      return {
        show:false,
        labelCol: { span: 5 },
        wrapperCol: { span: 16 },
        loading: false,
        pageFilter: {
          pageNo: 1,
          pageSize: 10,
        },
        pageData: {
           
        },
        columns:[
          {
            title: '序号',
            dataIndex: 'order',
            width: 60,
            align: 'center',
            customRender: (text, record, index) =>
              `${(this.pageFilter.pageNo - 1) * this.pageFilter.pageSize + (index + 1)}` //序号分页后连续
          },
          {
            title: '抽检编号',
            dataIndex: 'randomNo',
            align: 'center',
            width:90
          },
          {
            title: '抽检类型',
            dataIndex: 'randomType',
            align: 'center',
            width:90
          },
          {
            title: '抽检周期',
            dataIndex: 'cycle',
            align: 'center',
            width:90
          },
          {
            title: '抽检范围',
            dataIndex: 'time',
            align: 'center',
            width:90
          },
          {
            title: '范围总量',
            dataIndex: 'amountRange',
            align: 'center',
            width:90
          },
          {
            title: '抽检方式',
            dataIndex: 'randomWay',
            align: 'center',
            width:90
          },
          {
            title: '抽检比例',
            dataIndex: 'randomProportion',
            align: 'center',
            width:90
          },
          {
            title: '抽检数量',
            dataIndex: 'randomNumber',
            align: 'center',
            width:90
          },
          {
            title: '移动验证数量',
            dataIndex: 'mobileBlockingNumber',
            align: 'center',
            width:120
          },
          {
            title: '移动验证率',
            dataIndex: 'mobileBlockingRate',
            align: 'center',
            width:110
          },
          {
            title: '联通验证数量',
            dataIndex: 'unicomBlockingNumber',
            align: 'center',
            width:120
          },
          {
            title: '联通验证率',
            dataIndex: 'unicomBlockingRate',
            align: 'center',
            width:110
          },
          {
            title: '电信验证数量',
            dataIndex: 'telecomBlockingNumber',
            align: 'center',
            width:120
          },
          {
            title: '电信验证率',
            dataIndex: 'telecomBlockingRate',
            align: 'center',
            width:110
          },
          {
            title: '抽检人',
            dataIndex: 'randomPerson',
            align: 'center',
            width:80
          },
          {
            title: '抽取时间',
            dataIndex: 'randomTime',
            align: 'center',
            width:90
          },
          {
            title: '抽检状态',
            dataIndex: 'randomStatus',
            align: 'center',
            width:90
          },
          {
            title: '抽检完成时间',
            dataIndex: 'randomDoneTime',
            align: 'center',
            width:120
          },
          {
            title: '操作',
            dataIndex: 'action',
            align: 'center',
            scopedSlots: { customRender: 'action' },
            width:180,
            fixed: 'rigth'
          },

        ]
      }
    },
    methods: {
      onTimeChange(date) {
      this.$set(this.pageFilter, 'startTime', date[0])
      this.$set(this.pageFilter, 'endTime', date[1])
      },
      Add(){
        this.$router.push({
        path: '/plugging/police/HandlVerification/Add',
        query: {}
      })
      },
      Edit(record){
        this.$router.push({
        path: '/plugging/police/HandlVerification/Add',
        query: {
            type:'edit',
            id:record.id
        }
      })
      },
      Details(record){
        this.$router.push({
        path: '/plugging/police/HandlVerification/Add',
        query: {
          type:'Details',
          id:record.id
        }
      })
      },
      Report(){
        this.$router.push({
        path: '/plugging/police/HandlVerification/Report',
        query: {}
      })
      },
      onQuery() {
        this.pageFilter.pageNo = 1
        this.refreshTable()
      },
      //重置
      onResetForm() {
        this.pageFilter = {
          pageNo: 1,
          pageSize: 10,
          departmentId: this.departmentId
        }
        this.refreshTable()
      },
      onSelectedRow(keys) {
        this.selectKeys = keys
        this.isDisabled = keys.length > 0 ? false : true
      },
      onTableChange(pagination, pageFilter, sorter) {
        let keyMap = { currentPage: 'pageNo' }
        let paginations = Object.keys(pagination).reduce((newData, key) => {
          let newKey = keyMap[key] || key
          newData[newKey] = pagination[key]
          return newData
        }, {})
        this.pageFilter = Object.assign({}, this.pageFilter, paginations)
        this.refreshTable()
      },
      refreshTable() {
        this.loading = true
        pageBlockingHandRandom(this.pageFilter).then( res => {
          if (res.success) {
            this.pageData = res.result ? res.result : {}
            this.loading = false
          } else {
            this.$message.success(res.message)
            this.loading = false
          }
        })
          .catch((e) => {
            this.loading = false
            this.$message.warn('请求失败！')
          })
      },
      yanzheng(record){
        let obj = {
          unsealExtractionList:[]
        }
        obj.listBlockingQuickReportDto.push(record)
        // console.log(obj);
        modifyBlockingHandRandom(obj).then( res => {
          if (res.success) {
            this.$message.success(res.message)
            this.loading = false
          } else {
            this.$message.success(res.message)
            this.loading = false
          }
        })
          .catch((e) => {
            this.loading = false
            this.$message.warn('请求失败！')
          })
      }
    }
  }
  </script>
  
  <style lang="less" scoped>
  .search-wrapper-btn {
    position: absolute;
    right: 8%;
    top: 22px;
    z-index: 100;
  }
  </style>